﻿Imports System.Drawing
Public Class SelectFunction
  Private Shared _funcs As List(Of String) = Nothing

  Public Sub New()
    Me.InitializeComponent()
    Me.NumericUpDownArgument.Minimum = Integer.MinValue
    Me.NumericUpDownArgument.Maximum = Integer.MaxValue
    If _funcs Is Nothing Then
      _funcs = New List(Of String)
      For Each bt As Integer In ControlFunctions.GetAllValidButtons
        Dim btstr As String = bt.ToString("000")
        _funcs.Add(btstr & " " & Language.GetLanguageString("Control" & btstr))
      Next
    End If
    Me.ComboBoxFunction.Items.Clear()
    For Each s As String In _funcs
      Me.ComboBoxFunction.Items.Add(s)
    Next
    Me.ComboBoxFunction.SelectedIndex = 0

    Me.LabelFunction.Text = Language.GetLanguageString("Control")
    Me.LabelParameter.Text = Language.GetLanguageString("Parameter")
  End Sub

  Public Overrides Property BackColor() As System.Drawing.Color
    Get
      Return MyBase.BackColor
    End Get
    Set(ByVal value As System.Drawing.Color)
      MyBase.BackColor = value
      Me.LabelFunction.BackColor = value
      Me.LabelParameter.BackColor = value
    End Set
  End Property

  Public Overrides Property ForeColor() As System.Drawing.Color
    Get
      Return MyBase.ForeColor
    End Get
    Set(ByVal value As System.Drawing.Color)
      MyBase.ForeColor = value
      Me.LabelFunction.ForeColor = value
      Me.LabelParameter.ForeColor = value
      Me.ComboBoxFunction.ForeColor = value
      Me.NumericUpDownArgument.ForeColor = value
    End Set
  End Property

  Public Property BackColorTextbox() As Color
    Get
      Return Me.ComboBoxFunction.BackColor
    End Get
    Set(ByVal value As Color)
      Me.ComboBoxFunction.BackColor = value
      Me.NumericUpDownArgument.BackColor = value
    End Set
  End Property

  Public Property SelectedFunction() As Integer
    Get
      Dim btstr As String = ComboBoxFunction.SelectedItem.ToString.Substring(0, 3)
      Dim bt As Integer = Integer.Parse(btstr)
      Return bt
    End Get
    Set(ByVal value As Integer)
      Dim btstr As String = value.ToString("000")
      For i As Integer = 0 To Me.ComboBoxFunction.Items.Count - 1
        If btstr = Me.ComboBoxFunction.Items(i).ToString.Substring(0, 3) Then
          Me.ComboBoxFunction.SelectedIndex = i
          Exit For
        End If
      Next
    End Set
  End Property

  Public Property SelectedParameter() As Integer
    Get
      Return CInt(Me.NumericUpDownArgument.Value)
    End Get
    Set(ByVal value As Integer)
      Me.NumericUpDownArgument.Value = value
    End Set
  End Property

  Private Sub ComboBoxFunction_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBoxFunction.SelectedIndexChanged
    Dim en As Boolean = ControlFunctions.IsControlFunctionWithParamter(Me.SelectedFunction)
    Me.NumericUpDownArgument.Enabled = en
    Me.LabelParameter.Enabled = en
  End Sub
End Class
